<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>报关报检业务历史数据列表</title>
    <jsp:include page="../../head.jsp"/>
</head>
<script type="text/javascript">
    var formSetting = {
        title: "报关报检业务历史数据列表查询",
        module: 'query',
        columns: [{
            name: "state",
            label: "业务状态",
            type: "dropdown",
            dropdownType: "ajax",
            url: "../base/dropdown-declarationState",
            op: "eq",
            minLength: 0
        }, {
            name: "CTIME",
            label: "业务提交时间从",
            type: "date"
        }, {
            name: "CTIME",
            label: "到",
            type: "date"
        }],
        buttons: {
            custom: [
                {
                    id: "query", value: "获取数据", click: function () {
                    var selectedRowId = $("#declarationsDataGrid").getGridParam("selrow");
                    if (selectedRowId) {
                        var selectedRow = $("#declarationsDataGrid").getRowData(selectedRowId);
                        parent.loadBizFromHistoryData(selectedRow.businessId, "declaration");
                        jw.close();
                    }
                    else {
                        jw.alert("请点击需要操作的数据!");
                    }
                }
                }
            ]
        },
        grid: {
            id: "declarationsDataGrid",
            title: "查询结果",
            autowidth: false,
            url: "declaration-findList?loadPage=${loadPage}",
            /* postData : {
             "pid" : pid
             }, */
            colModel: [{
                index: "ID",
                name: "id",
                hidden: true
            }, {
                index: "businessId",
                name: "businessId",
                hidden: true
            }, {
                index: "supNAME",
                name: "supCompany.name",
                label: "业务供应商"
            }, {
                index: "shipper",
                name: "shipper.company",
                label: "实际托运人"
            }, {
                index: "confirmTime",
                name: "confirmTime",
                label: "业务提交时间",
                formatter: 'date',
                formatoptions: {srcformat: 'Y-m-d H:i:s', newformat: 'Y-m-d H:i:s'}
            }, {
                index: "validateState",
                name: "state",
                label: "业务状态"
            }, {
                index: "operateState",
                name: "operateState",
                label: "业务操作进度"
            }, {
                index: "informState",
                name: "declarationInform.confirmState",
                label: "资料寄送提醒进度"
            }],
            sortname: "confirmTime",
            sortorder: "desc",
            jsonReader: {
                root: "declarations"
            },
            loadComplete: function (data) {
                var ids = $("#declarationsDataGrid").getDataIDs();
                for (var i = 0; i < ids.length; i++) {
                    var arrayData = $("#declarationsDataGrid").getRowData(ids[i]);
// 					if(arrayData.state=="已上传") {
                    if (arrayData.state == "安排中") {
                        $("#declarationsDataGrid").setCell(ids[i], "operateState",
                                                           "<span style='cursor:pointer;' onclick=\"findBizState(\'"
                                                           + i + "\', 'state', \'" + arrayData.id
                                                           + "\');\"><font color='red'>点击查看</font><span>");
                    }
                    else if (arrayData.state == "已完成") {
                        $("#declarationsDataGrid").setCell(ids[i], "operateState",
                                                           "<span style='cursor:pointer;' onclick=\"findBizState(\'"
                                                           + i + "\', 'state', \'" + arrayData.id
                                                           + "\');\">点击查看<span>");
                        //$("#declarationsDataGrid").setCell(ids[i], "operateState", "业务已完成");
                        $($("#" + arrayData.id).find("td")[6]).addClass("biz_state_finish");
                    }
                    else {
// 						$("#declarationsDataGrid").setCell(ids[i], "operateState", "业务未上传");
                        $("#declarationsDataGrid").setCell(ids[i], "operateState", "业务未安排");
                    }
                    if ($(arrayData).attr('declarationInform.confirmState') == "0") {
                        $("#declarationsDataGrid").setCell(ids[i], "declarationInform.confirmState",
                                                           "已发送，待确认");
                    }
                    else if ($(arrayData).attr('declarationInform.confirmState') == "1") {
                        $("#declarationsDataGrid").setCell(ids[i], "declarationInform.confirmState",
                                                           "已确认接收");
                        $($("#" + arrayData.id).find("td")[7]).addClass("biz_state_finish");
                    }
                    else {
                        $("#declarationsDataGrid").setCell(ids[i], "declarationInform.confirmState",
                                                           "未发送");
                    }
                }
            }
        }
    };
    $(document).ready(function () {
        $("#declarationsDataTable").mrdForm(formSetting);
    });

    function setGridCell(i, name, value) {
        var ids = $("#declarationsDataGrid").getDataIDs();
        $("#declarationsDataGrid").setCell(ids[i], name, value);
    }

    function findBizResult(bizId) {
        jw.dialog({iframe: 'declaration-findBizResult?id=' + bizId});
    }

    function findBizState(i, colName, bizId) {
        var data = "id=" + bizId;
        $.ajax({
                   url: "declaration-findBizState",
                   cache: false,
                   dataType: "json",
                   data: data,
                   success: function (data) {
                       setGridCell(i, colName, data.msg);
                   }
               });
        setGridCell(i, colName, "loadding...");
        findBizResult(bizId);
    }
</script>
<body>
<div id="declarationsDataTable"></div>
</body>
</html>
